package com.sykj.service.impl;

import com.sykj.bean.DianZhan;
import com.sykj.service.DianZhanService;
import com.sykj.service.ProjectdianService;
import com.sykj.util.RedisKeys;
import com.sykj.util.redis.RedisUtil;
import com.sykj.util.reponse.CommonEnum;
import com.sykj.util.reponse.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;

/**
 * @program: BeautyClub
 * @description:
 * @author: qiaoli
 * @create: 2020-08-13 22:05
 */
@Service
public class ProjectdianServiceImpl   implements ProjectdianService {

@Autowired
    DianZhanService dianZhanService;
    @Override
    public ResultBody savashuByRedis(String projectId) {

         //记录浏览量到redis,然后定时更新到数据库
        String key=RedisKeys.ARTICLE_VIEWCOUNT_CODE+projectId;
        //找到redis中该护理项目的浏览数，如果不存在则向redis中添加一条
        Map<Object,Object> viewCountItem=RedisUtil.hmget(RedisKeys.ARTICLE_VIEWCOUNT_KEY);
        Integer viewCount=0;
        // 判断是否存在ip
        if(!viewCountItem.isEmpty()){
            if(viewCountItem.containsKey(key)){
                viewCount=(Integer)viewCountItem.get(key);
                RedisUtil.hset(RedisKeys.ARTICLE_VIEWCOUNT_KEY,key,viewCount+1);
                System.err.println("浏览量+1");
            }else {
                RedisUtil.hset(RedisKeys.ARTICLE_VIEWCOUNT_KEY,key,1);
                System.err.println("浏览量  初始化");
            }
        }else{
            RedisUtil.hset(RedisKeys.ARTICLE_VIEWCOUNT_KEY,key,1);

            System.err.println("浏览量  初始化");
        }


        return new ResultBody(CommonEnum.SUCCESS);
    }
}
